import sun.reflect.generics.tree.Tree;

import javax.xml.soap.Node;
import java.util.List;


/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: DickYang
 * Date: 2023-07-12
 * Time: 15:06
 */
public class TestMyBinaryTree {


    public static void main(String[] args) {
        MyBinaryTree myBinaryTree = new MyBinaryTree();
        MyBinaryTree.TreeNode root = myBinaryTree.createTree();

        //前序遍历
        System.out.print("前序遍历: ");
        myBinaryTree.preOrder(root);
        System.out.println();

        //中序遍历
        System.out.print("中序遍历: ");
        myBinaryTree.inOrder(root);
        System.out.println();

        //后序遍历
        System.out.print("后序遍历: ");
        myBinaryTree.postOrder(root);
        System.out.println();

        //节点的个数
        int count = myBinaryTree.size(root);
        System.out.println("节点的个数：" + count);

        //叶子节点的个数
        int count1 = myBinaryTree.getLeafTreeNodeCount(root);
        System.out.println("叶子节点的个数: " + count1);

        //第K层的节点数
        int count2 = myBinaryTree.getKLevelTreeNodeCount(root,3);
        System.out.println("第三层节点的个数: " + count2);

        //检测值为value的元素是否存在
        MyBinaryTree.TreeNode node = myBinaryTree.find(root,'H');
        System.out.println(node.val);

        //层序遍历
        System.out.print("层序遍历: ");
        myBinaryTree.levelOrder(root);
        System.out.println();

        //公共祖先
        MyBinaryTree.TreeNode p = myBinaryTree.find(root,'E');
        MyBinaryTree.TreeNode q = myBinaryTree.find(root,'C');
        System.out.print(p.val + "和" + q.val + "公共祖先: ");
        MyBinaryTree.TreeNode ret = myBinaryTree.lowestCommonAncestor2(root,p,q);
        System.out.println(ret.val);

        //判断一个数是不是完全二叉树
        System.out.print("是否为完全二叉树: ");
        System.out.println(myBinaryTree.isCompleteTree(root));
    }
}


